#ifndef HBOT_H
#define HBOT_H

#include <QComboBox>
#include <QDialogButtonBox>
#include <QMutex>
#include <QPushButton>
#include <QtGui/QGroupBox>
#include <QtGui/QMainWindow>
#include <QtGui/QTextBrowser>
#include <QSqlTableModel>
#include <QTableView>

#include "hbot_class.h"
#include "singleton.h"
#include "ui_hbot.h"

#define MENU_SELECT_ACTION_EMPTYPROFILELIST "Empty (Create a profile)"

#define PRINT_CONSOLE_GROUP_BNET			"BNET"
#define PRINT_CONSOLE_GROUP_CONFIG			"CONFIG"
#define PRINT_CONSOLE_GROUP_DATABASE		"DB"
#define PRINT_CONSOLE_GROUP_HBOT			"HBOT"
#define PRINT_CONSOLE_GROUP_LOG				"LOG"
#define PRINT_CONSOLE_GROUP_SIGNAL			"SIGNAL"

#define PRINT_CONSOLE_GROUP_BNET_COLOR		"#660000"
#define PRINT_CONSOLE_GROUP_CONFIG_COLOR	"green"
#define PRINT_CONSOLE_GROUP_DATABASE_COLOR	"#FCC200"
#define PRINT_CONSOLE_GROUP_HBOT_COLOR		"blue"
#define PRINT_CONSOLE_GROUP_LOG_COLOR		"gray"
#define PRINT_CONSOLE_GROUP_SIGNAL_COLOR	"orange"

class CXMLConfig;

class HBot: public QMainWindow, public Ui::HBotClass, public Singleton<HBot>
{
	Q_OBJECT

private:
	bool m_BotRunning;
	bool m_InterfaceInitialized;

	CXMLConfig *m_XMLProfile;
	CHBot *m_Bot;
	QAction *m_ActionEmptyProfileList;
	QString m_CurrentProfile;
	QVector<QAction *> m_SelectMenuProfiles;

	// Main Window Interface

	QComboBox *m_DatabaseComboBox;
	QDialogButtonBox *m_DatabaseButtonBox;
	QDialogButtonBox *m_DatabaseButtonBox2;
	QGroupBox *m_HBotGroupBox;
	QHBoxLayout *m_DatabaseHorizontalLayout;
	QMutex *m_PrintMutex;
	QPushButton *m_DatabaseConnectButton;
	QPushButton *m_DatabaseDeleteRowButton;
	QPushButton *m_DatabaseDisconnectButton;
	QPushButton *m_DatabaseInsertRowButton;
	QPushButton *m_DatabaseSubmitButton;
	QSqlTableModel *m_DatabaseTable;
	QTableView *m_DatabaseTableView;
	QTabWidget *m_BNETTabWidget;
	QTabWidget *m_HBotInterface;
	QTextBrowser *m_BNETOutputBrowser;
	QTextBrowser *m_OutputBrowser;
	QVBoxLayout *m_HBotVerticalLayout;
	QVBoxLayout *m_HBotVerticalLayoutMain;
	QVBoxLayout *m_TabVerticalLayout;
	QVBoxLayout *m_TabVerticalLayoutDatabase;
	QVector<QGroupBox *> m_BNETGroupBox;
	QVector<QVBoxLayout *> m_BNETVerticalLayout;
	QVector<QVBoxLayout *> m_BNETVerticalLayoutMain;
	QVector<QWidget *> m_BNETTabs;
	QWidget *m_TabBattlenet;
	QWidget *m_TabDatabase;
	QWidget *m_TabHBot;

private:
	virtual void closeEvent(QCloseEvent *event);

private slots:
	void ActionCloseApplication();
	void ActionDatabaseComboBoxChanged(int index);
	void ActionDeleteRowDatabase();
	void ActionInsertRowDatabase();
	void ActionOpenDatabase();
	void ActionProfileManager();
	void ActionSelectProfile();
	void ActionSubmitChangesDatabase();
	bool ActionCloseDatabase(bool button = true);

public:
	HBot(QWidget *parent = 0, Qt::WFlags flags = 0);
	~HBot();

	void CreateProfileDirectory(const QString &profile);
	void InitializeInterface();
	void OpenProfile(const QString &profile);
	bool ContainsInvalidCharacters(const QString &profile);
	bool DeleteDirectory(const QString &profile);

	QAction *GetActionEmptyProfileList() const											{ return m_ActionEmptyProfileList; }
	QMenu *GetMenuSelectProfile() const													{ return menuSelect_Profile; }
	QString GetCurrentProfile() const													{ return m_CurrentProfile; }
	QVector<QAction *> GetSelectMenuProfiles() const									{ return m_SelectMenuProfiles; }
	CXMLConfig *GetXMLProfile()	const													{ return m_XMLProfile; }

	void SetActionEmptyProfileList(void *ptr)											{ m_ActionEmptyProfileList = (QAction *) ptr; }


public slots:
	void PrintConsole(const QString &group, const QString &message, const QString &subGroup = QString(), bool error = 0);
	bool CloseProfile();

	void SetOpenDatabase(bool enabled)													{ m_DatabaseConnectButton->setEnabled(enabled); }
};

#endif // HBOT_H
